﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using net.windward.api.csharp;
using System.Net.Mime;

namespace ArrowCore
{
    public class ExtensionConvert
    {
        /// <summary>
        /// Convert to the common file extension. Does not include the period.
        /// </summary>
        /// <param name="format">The format to convert.</param>
        /// <returns>"html", "pdf", "rtf", "xml", or "txt". "xml" is for both WordML and SpreadsheetML.</returns>
        public static string ToExtension(Report.REPORT_TYPE format)
        {
            switch (format)
            {
                case Report.REPORT_TYPE.DOCX:
                    return "docx";
                case Report.REPORT_TYPE.HTML:
                    return "html";
                case Report.REPORT_TYPE.PDF:
                    return "pdf";
                case Report.REPORT_TYPE.PPTX:
                    return "pptx";
                case Report.REPORT_TYPE.RTF:
                    return "rtf";
                case Report.REPORT_TYPE.SPREAD_ML:
                    return "xml";
                case Report.REPORT_TYPE.TXT:
                    return "txt";
                case Report.REPORT_TYPE.WORD_ML:
                    return "xml";
                case Report.REPORT_TYPE.XLS:
                    return "xls";
                case Report.REPORT_TYPE.XLSX:
                    return "xlsx";
                default:
                    throw new ArgumentException("unknown format " + format);
            }
        }

        /// <summary>
        /// Convert to the http content type.
        /// </summary>
        /// <param name="format">The format to convert.</param>
        /// <returns>"body/text", "application/msword", etc.</returns>
        public static string ToContentType(Report.REPORT_TYPE format)
        {

            switch (format)
            {
                case Report.REPORT_TYPE.HTML:
                    return MediaTypeNames.Text.Html;
                case Report.REPORT_TYPE.PDF:
                    return MediaTypeNames.Application.Pdf;
                case Report.REPORT_TYPE.PPTX:
                    return "application/vnd.ms-powerpoint";
                case Report.REPORT_TYPE.RTF:
                    return MediaTypeNames.Application.Rtf;
                case Report.REPORT_TYPE.SPREAD_ML:
                case Report.REPORT_TYPE.XLS:
                case Report.REPORT_TYPE.XLSX:
                    return "application/vnd.ms-excel";
                case Report.REPORT_TYPE.TXT:
                    return MediaTypeNames.Text.Plain;
                case Report.REPORT_TYPE.WORD_ML:
                case Report.REPORT_TYPE.DOCX:
                    return "application/msword";
                default:
                    throw new ArgumentException("unknown format " + format);
            }
        }
    }
}
